package com.gitee.kerraway.recursion;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author 小柯
 * @date 2018/3/25
 */
public class LinkedListCreator {

  public static void main(String[] args) {
    LinkedListCreator creator = new LinkedListCreator();

    Node.print(creator.createLinkedList(null));
    Node.print(creator.createLinkedList(Collections.emptyList()));
    Node.print(creator.createLinkedList(Collections.singletonList(1)));
    Node.print(creator.createLinkedList(Arrays.asList(1, 2, 3, 4)));
  }

  public Node createLinkedList(List<Integer> data) {
    if (data == null || data.isEmpty()) {
      return null;
    }
    Node node = new Node(data.get(0));
    node.setNext(this.createLinkedList(data.subList(1, data.size())));
    return node;
  }

}
